const KoaRouter = require('koa-router')
const HttpClient = require('../util/HttpClient')
const Template = require('../util/Template')

const router = new KoaRouter();
const modules = require('../../modules');

router.get('/setting/doMyself/:type', async ctx => {
  let script = ['/doMyself.home.js'];
  let modConfig = modules['doMyself.home'];
  let reqHeaders = ctx.request.headers;
  let result = await HttpClient.request(`/setting/doMyself/${ctx.params.type}`, 'get', null, { headers: reqHeaders });
  let body = result.body;
  ctx.body = await Template.renderWithHtml('自助门户设置', body, script, modConfig.template, ctx)
});

router.get('/setting/doMyself/wxSet', async ctx => {
  let script = ['/doMyself.home.js'];
  let modConfig = modules['doMyself.home'];
  let reqHeaders = ctx.request.headers;
  let result = await HttpClient.request('/setting/doMyself/wxSet', 'get', null, { headers: reqHeaders });
  let body = result.body;
  ctx.body = await Template.renderWithHtml('自助门户设置', body, script, modConfig.template, ctx)
});

router.get('/setting/doMyself/toastList', async ctx => {
  let script = ['/doMyself.home.js'];
  let modConfig = modules['doMyself.home'];
  let reqHeaders = ctx.request.headers;
  let result = await HttpClient.request('/setting/doMyself/miniProgramSet', 'get', null, { headers: reqHeaders });
  let body = result.body;
  ctx.body = await Template.renderWithHtml('消息设置', body, script, modConfig.template, ctx)
});

router.get('/setting/doMyself/miniProgramSet', async ctx => {
  let script = ['/doMyself.home.js'];
  let modConfig = modules['doMyself.home'];
  let reqHeaders = ctx.request.headers;
  let result = await HttpClient.request('/setting/doMyself/toastList', 'get', null, { headers: reqHeaders });
  let body = result.body;
  ctx.body = await Template.renderWithHtml('自助门户设置', body, script, modConfig.template, ctx)
});
router.get('/setting/message', async ctx => {
  let script = ['/doMyself.message.js'];
  let modConfig = modules['doMyself.message'];
  let reqHeaders = ctx.request.headers;
  let result = await HttpClient.request('/setting/message', 'get', null, { headers: reqHeaders });
  let body = result.body;
  ctx.body = await Template.renderWithHtml('消息设置', body, script, modConfig.template, ctx)
});

router.get('/setting/message/subManage', async ctx => {
  let script = ['/doMyself.subManage.js'];
  let modConfig = modules['doMyself.subManage'];
  let reqHeaders = ctx.request.headers;
  let result = await HttpClient.request('/setting/message/subManage', 'get', null, { headers: reqHeaders });
  let body = result.body;
  ctx.body = await Template.renderWithHtml('订阅通知管理', body, script, modConfig.template, ctx)
});

router.get('/setting/message/smsMessage', async ctx => {
  let script = ['/doMyself.smsMessage.js'];
  let modConfig = modules['doMyself.smsMessage'];
  let reqHeaders = ctx.request.headers;
  let result = await HttpClient.request('/setting/message/smsmessage', 'get', null, { headers: reqHeaders });
  let body = result.body;
  ctx.body = await Template.renderWithHtml('短信消息设置', body, script, modConfig.template, ctx)
});

module.exports = router;
